package org.jarraiders.musiclibrary.client.view;

import org.jarraiders.musiclibrary.client.presenter.EditArtistPresenter;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class EditArtistView extends Composite implements EditArtistPresenter.Display {
	private final TextBox artistName;
	private final FlexTable detailsTable;
	private final Button saveButton;
	private final Button cancelButton;
	
	public EditArtistView() {
	    DecoratorPanel contentDetailsDecorator = new DecoratorPanel();
	    contentDetailsDecorator.setWidth("18em");
	    initWidget(contentDetailsDecorator);

	    VerticalPanel contentDetailsPanel = new VerticalPanel();
	    contentDetailsPanel.setWidth("100%");

	    // Create the contacts list
	    //
	    detailsTable = new FlexTable();
	    detailsTable.setCellSpacing(0);
	    detailsTable.setWidth("100%");
	    detailsTable.addStyleName("contacts-ListContainer");
	    detailsTable.getColumnFormatter().addStyleName(1, "add-contact-input");
	    artistName = new TextBox();
	    initDetailsTable();
	    contentDetailsPanel.add(detailsTable);
	    
	    HorizontalPanel menuPanel = new HorizontalPanel();
	    saveButton = new Button("Save");
	    cancelButton = new Button("Cancel");
	    menuPanel.add(saveButton);
	    menuPanel.add(cancelButton);
	    contentDetailsPanel.add(menuPanel);
	    contentDetailsDecorator.add(contentDetailsPanel);
	  }
	private void initDetailsTable() {
	    detailsTable.setWidget(0, 0, new Label("Artist name"));
	    detailsTable.setWidget(0, 1, artistName);	    
	    artistName.setFocus(true);
	  }
	
	@Override
	  public HasClickHandlers getSaveButton() {
	    return saveButton;
	  }
	@Override
	  public HasClickHandlers getCancelButton() {
	    return cancelButton;
	  }
	@Override
	  public Widget asWidget() {
	    return this;
	  }
	@Override
	public HasValue<String> getArtistName() {
		
		return artistName;
	}
	
}
